package com.gxan.dao.impl;

import com.gxan.common.Constants;
import com.gxan.dao.HumanDao;
import com.gxan.dbutils.JdbcBuild;
import com.gxan.pojo.Human;

import java.sql.SQLException;
import java.util.List;

public class HumanDaoImpl extends JdbcBuild implements HumanDao {
    @Override
    public int saveHuman(Human human) throws SQLException {
        String sql = "insert into human(human_name,human_sex,human_birthday,human_education,human_email," +
                "human_tel,dept_id,human_resume) values(?,?,?,?,?,?,?,?)";
        Object[] params = {human.getHuman_name(), human.getHuman_sex(), human.getHuman_birthday(), human.getHuman_education(),
                human.getHuman_email(), human.getHuman_tel(), human.getDept_id(), human.getHuman_resume()};
        return super.executeUpdate(sql, params);
    }

    @Override
    public Integer countHuman() throws SQLException {
        //如果表中的数据不是删除状态，就查询总记录数
        String sql = "select count(*) from human where file_status !=?";
        Object[] params = {Constants.STATUS_DEL};
        return super.findAllForInt(sql, params);
    }

    @Override
    public Integer reviewCountHuman() throws SQLException {
        //如果表中的数据是审核中的状态，就查询总记录数
        String sql = "select count(*) from human where file_status =?";
        Object[] params = {Constants.STATUS_REVIEWING};
        return super.findAllForInt(sql, params);
    }

    @Override
    public Integer reviewSearchCountHuman(String human_name) throws SQLException {
        //根据姓名查询审核中状态的总记录数
        int result = -1;
        if (human_name != null && !"".equals(human_name)) {
            String sql = "select count(*) from human where file_status =? and human_name = ?";
            Object[] params = {Constants.STATUS_REVIEWING, human_name};
            result = super.findAllForInt(sql, params);
        } else {
            String sql = "select count(*) from human where file_status =?";
            Object[] params = {Constants.STATUS_REVIEWING};
            result = super.findAllForInt(sql, params);

        }
        return result;
    }

    @Override
    public List<Human> queryHumanList(Integer param01, Integer param02) throws SQLException {
        String sql = "select * from human where file_status !=? limit ?,?";
        Object[] params = {Constants.STATUS_DEL, param01, param02};
        return super.queryListEntity(Human.class, sql, params);
    }

    @Override
    public List<Human> reviewQueryHumanList(Integer param01, Integer param02) throws SQLException {
        String sql = "select * from human where file_status =? limit ?,?";
        Object[] params = {Constants.STATUS_REVIEWING, param01, param02};
        return super.queryListEntity(Human.class, sql, params);
    }

    @Override
    public List<Human> reviewQueryHumanList(Integer param01, Integer param02, String human_name) throws SQLException {
        if (human_name != null && !"".equals(human_name)) {
            String sql = "select * from human where file_status =? and human_name = ? limit ?,?";
            Object[] params = {Constants.STATUS_REVIEWING, human_name, param01, param02};
            return super.queryListEntity(Human.class, sql, params);
        } else {
            String sql = "select * from human where file_status =? limit ?,? ";
            Object[] params = {Constants.STATUS_REVIEWING, param01, param02};
            return super.queryListEntity(Human.class, sql, params);
        }
    }

    @Override
    public int updateHuman(Human human) throws SQLException {
        String sql = "update human set human_name = ?,human_sex = ?,human_birthday = ?,human_education = ?,human_email = ?," +
                "human_tel = ?,dept_id = ?,human_resume = ? where human_id = ?";
        Object[] params = {human.getHuman_name(), human.getHuman_sex(), human.getHuman_birthday(), human.getHuman_education(),
                human.getHuman_email(), human.getHuman_tel(), human.getDept_id(), human.getHuman_resume(), human.getHuman_id()};
        return super.executeUpdate(sql, params);
    }

    @Override
    public int delHumanById(String human_id, Integer statusDel) throws SQLException {
        String sql = "update human set file_status = ? where human_id = ?";
        Object[] params = {statusDel, human_id};
        return super.executeUpdate(sql, params);
    }

    @Override
    public Integer countHuman(String human_name) throws SQLException {
        int result = -1;
        if (human_name != null && !"".equals(human_name)) {
            String sql = "select count(*) from human where file_status !=? and human_name = ?";
            Object[] params = {Constants.STATUS_DEL, human_name};
            result = super.findAllForInt(sql, params);
        } else {
            String sql = "select count(*) from human where file_status !=?";
            Object[] params = {Constants.STATUS_DEL};
            result = super.findAllForInt(sql, params);

        }
        return result;
    }

    @Override
    public List<Human> queryEmployeeList(Integer param01, Integer param02, String human_name) throws SQLException {
        if (human_name != null && !"".equals(human_name)) {
            String sql = "select * from human where file_status !=? and human_name = ? limit ?,?";
            Object[] params = {Constants.STATUS_DEL, human_name, param01, param02};
            return super.queryListEntity(Human.class, sql, params);
        } else {
            String sql = "select * from human where file_status !=? limit ?,? ";
            Object[] params = {Constants.STATUS_DEL, param01, param02};
            return super.queryListEntity(Human.class, sql, params);
        }
    }

//    @Override
//    public int toCheck(String human_id, Integer statusReviewing) throws SQLException {
//
//        String sql = "update human set file_status = ? where human_id = ?";
//        Object[] params = {statusReviewing, human_id};
//        return super.executeUpdate(sql, params);
//    }

    @Override
    public int changeCheckStatus(String human_id, Integer checkStatus) throws SQLException {
        String sql = "update human set file_status = ? where human_id = ?";
        Object[] params = {checkStatus, human_id};
        return super.executeUpdate(sql, params);
    }

}
